package com.leaves.contoller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.leaves.entity.dto.LoginUser;
import com.leaves.response.ApiResult;
import com.leaves.service.UserInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author LEAVES
 * @Date 2022/4/30 15:32
 * @Version 1.0
 */
@RestController
@RequestMapping("/v1")
public class LoginController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 获取验证码
     *
     * @param response
     */
    @GetMapping("/code")
    public void getVerifyCode(HttpServletResponse response) {
        userInfoService.createVerifyCode(response);
    }

    /**
     * 登录
     *
     * @param loginUser
     * @param response
     * @return
     */
    @RequestMapping("/login")
    public ApiResult loginCheck(@Validated LoginUser loginUser, HttpServletResponse response) {
        return userInfoService.loginCheck(loginUser, response);
    }
}
